package middleware

import (
	"fmt"
	"time"

	"github.com/gin-gonic/gin"
)

// 中间件学习
func StudyMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		t := time.Now()
		println("这是一个学习中间件，处理请求前的逻辑", t.Format("2006-01-02 15:04:05"))
		c.Set("request_time", t.Format("2006-01-02 15:04:05"))
		status := c.Writer.Status()
		println("响应状态码:", status)
		t2 := time.Since(t)
		fmt.Println("请求处理时间:", t2)
		c.Next()
	}
}
